﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.Text;
using Autorent.Desktop.Model;
using Autorent.Desktop.Model.AutorentMngrServiceReference;

namespace Autorent.Desktop.Modules.Autoes.Services
{
    public class AutoClassesRepository : AutorentEntitiesContext, IAutoClassesRepository
    {      

        public ObservableCollection<AutoClass> GetAutoClasses()
        {
            try
            {
                return new ObservableCollection<AutoClass>(Context.AutoClasses);
            }
            catch (Exception)
            {
                throw new AutorentModelException("Auto classes loading error!");
            }
        }

        public void AddAutoClass(AutoClass autoClass)
        {
            try
            {
                Context.AddToAutoClasses(autoClass);
                Context.SaveChanges();
            }
            catch (Exception)
            {
                throw new AutorentModelException("Add auto class error occured!");
            }
        }

        public void DeleteAutoClass(AutoClass autoClass)
        {
            try
            {
                Context.DeleteObject(Context.AutoClasses.Where(ac => ac.AutoClass_ID.Equals(autoClass.AutoClass_ID)));
                Context.SaveChanges();
            }
            catch (Exception)
            {
                throw new AutorentModelException("Delete auto class error occured!");
            }
        }
    }
}
